package org.dizena.blog.starter.config.demo0;

import java.util.HashMap;
import java.util.Map;

public class HeaderInheritableUtil {

    //使用InheritableThreadLocal，使得共享变量可被子线程继承
    private static final InheritableThreadLocal<Map<String, String>> headerMap = new InheritableThreadLocal<>() {
        @Override
        protected Map<String, String> initialValue() {
            return new HashMap<>();
        }
    };

    public static Map<String, String> get() {
        return headerMap.get();
    }

    public static void set(String key, String value) {
        headerMap.get().put(key, value);
    }

    public static void remove() {
        headerMap.remove();
    }
}

